package com.acceptable.qucun.file.mapper;

import com.acceptable.qucun.file.entity.template.FileDeleteItem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.lang.NonNull;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface FileDeleteMapper extends BaseMapper<FileDeleteItem> {

    void createTable(@NonNull @Param("userId") Integer userId);

    int dropTable(@NonNull @Param("userId") Integer userId);

    List<FileDeleteItem> selectAll(@NonNull @Param("userId") Integer userId);

    // 插入一项
    int insert(@Param("userId") @NonNull Integer userId,
               @Param("item") @NonNull FileDeleteItem item);

    int insertBatch(@NonNull @Param("userId") Integer userId,
                    @NonNull @Param("itemList") List<FileDeleteItem> itemList);

    // 根据fileId删除一项
    @Delete("DELETE FROM ${userId}_delete WHERE file_id=#{fileId}")
    int deleteByFileId(@NonNull @Param("userId") Integer userId,
                       @NonNull @Param("fileId") Long fileId);

    int deleteBatchByFileId(@NonNull @Param("userId") Integer userId,
                            @NonNull @Param("fileIdList") List<Long> fileIdList);

    int updateByFileId(@NonNull @Param("userId") Integer userId,
                       @NonNull @Param("item") FileDeleteItem item);

    int updateBatchByFileId(@NonNull @Param("userId") Integer userId,
                            @NonNull @Param("item") List<FileDeleteItem> itemList);

    // 根据fileId查询
    FileDeleteItem selectByFileId(@NonNull @Param("userId") Integer userId,
                                  @NonNull @Param("fileId") Long fileId);

    List<FileDeleteItem> selectBatchByFileId(@NonNull @Param("userId") Integer userId,
                                             @NonNull @Param("fileIdList") List<Long> fileIdList);

    List<FileDeleteItem> selectExpiredFile(@NonNull @Param("userId") Integer userId,
                                           @NonNull @Param("curTime")LocalDateTime curTime);
}
